import { _decorator, Component, Node } from 'cc';
import { SGame } from '../../sgame/SGame';
import { AudioManager, play_bgm, play_effect } from '../../sgame/audio/AudioManager';
import { Toggle, Slider } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('AudioTest')
export class AudioTest extends Component {

    start() {
        SGame.Init({});

        let bgmNode: Node = this.node.Child("bgm");
        bgmNode.OnClickChild("play", () => {
            play_bgm("test_resource/audio/bgm");
        });

        bgmNode.OnClickChild("stop", () => {
            AudioManager.instance.stopBgm();
        });

        bgmNode.OnChild("toggle", Toggle.EventType.TOGGLE, (toggle: Toggle) => {
            AudioManager.instance.bgmEnable = toggle.isChecked;
        });

        bgmNode.OnChild("volumn", "slide", (slider: Slider) => {
            AudioManager.instance.bgmVolumn = slider.progress;
        });

        let effectNode: Node = this.node.Child("effect");
        effectNode.OnClickChild("play1", () => {
            play_effect("test_resource/audio/effect1");
        });

        effectNode.OnClickChild("play2", () => {
            play_effect("test_resource/audio/effect2");
        });

        effectNode.OnChild("toggle", Toggle.EventType.TOGGLE, (toggle: Toggle) => {
            AudioManager.instance.effectEnable = toggle.isChecked;
        });

        effectNode.OnChild("volumn", "slide", (slider: Slider) => {
            AudioManager.instance.effectVolumn = slider.progress;
        });
    }
}
